package com.yuanthink.gwt.client.modules.user.member;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.yuanthink.gwt.client.eventbus.EventBus;
import com.yuanthink.gwt.client.modules.user.member.actions.MemberListAction;

/**
 * 
 * @author 06peng
 *
 */
public class MemberModule {

	private static MemberModule instance = null;
	public MemberListAction memberListAction;
	
	public MemberModule(EventBus eventBus) {
        memberListAction = new MemberListAction(eventBus);
    }

    public interface ModuleClient {
        void onSuccess(MemberModule instance);

        void onUnavailable();
    }

    public static void createAsync(final EventBus eventBus, final ModuleClient client) {
        GWT.runAsync(new RunAsyncCallback() {
            public void onFailure(Throwable err) {
                client.onUnavailable();
            }

            public void onSuccess() {
                if (instance == null) {
                    instance = new MemberModule(eventBus);
                }
                client.onSuccess(instance);
            }
        });
    }
}
